import random
from typing import *


class Solution:
    def canSortArray(self, nums: List[int]) -> bool:
        s = []
        c = []
        for i, num in enumerate(nums):
            if i == 0 or nums[i].bit_count() == nums[i - 1].bit_count():
                c.append(nums[i])
            else:
                c.sort()
                s.extend(c)
                c = [nums[i]]
        c.sort()
        s.extend(c)
        print(s)
        for i, num in enumerate(s):
            if i > 0 and num < s[i - 1]:
                return False
        return True


s = Solution()
print(s.canSortArray([8, 4, 2, 30, 15]))
for i in range(10):
    c = []
    for j in range(100):
        c.append(random.randint(1, 255))
    print(c)
